<?php include('elements/convert-form.html')?>
<?php if(isset($resources)):
$labels = $this->get_labels($resources);
?>
<div class="resources">
	<h1>Resources (<?php h(count($resources)) ?>):</h1>
	<!-- <a class="action edit" rel="edit" href="/editor?<?php h($_SERVER['QUERY_STRING'])?>">Edit in form</a>
	<a class="action edit" rel="edit" href="/editor/turtle?<?php h($_SERVER['QUERY_STRING'])?>">Edit as turtle</a> -->
<ol>
<?php foreach($resources as $uri => $properties):?>
	<li>
	<div about="<?php if (preg_match('/^\_\:(.*)$/', $uri, $m)) {
         h('[' . $uri . ']');
      }
      else {
        h($uri);
      }
     ?>" id="resource_<?php echo url_id($uri)?>" class="-rdf-Resource<?php if(isset($augmented_uris) AND in_array($uri, $augmented_uris)) echo ' augmented'?>" 	<?php if (!empty($properties[RDF.'type'])):?> typeof="<?php foreach(array_unique($properties[RDF.'type']) as $type):?><?php h($this->Convert->URI->to_qname($type['value'], $this->namespaces)->value()) ?>"<?php endforeach; endif; ?>>
	<h2 class="dc-title">
	<?php if (!empty($properties[RDF.'type'])): foreach(array_unique($properties[RDF.'type']) as $type):?>
		<span class="rdf-type" title="<?php h($type['value']) ?>"><?php h($this->Convert->URI->to_label($type['value'])) ?></span>
	<?php endforeach; endif; ?>
	<?php 
		$lang = LANGUAGE;
		$title = $Resources->to_resource($uri)->get_title(&$lang) 
	?>
<span property="rdfs:label" xmlns:rdfs="<?php echo RDFS ?>" xml:lang="<?php echo $lang ?>"><?php
		h(wordwrap($title,75,"\n", true)); 
	?> 
</span>	<?php if (preg_match('/(jpg)|(gif)|(png)/', $uri)):?>
		<img alt="image" src="<?php  h( $uri) ?>" width="20"/>
	<?php endif?>

	</h2>
	
		<dl>
			<?php if(strpos($uri,"_:")===0):?>
				<dt>Bnode ID</dt>
				<dd><?php echo $uri ?></dd>
			<?php else:?>
				<dt>URI</dt>
			
				<dd>

				<a class="convert" href="/?data-uri=<?php echo urlencode(htmlentities($uri)); ?>&amp;format=html"><?php h($uri) ?></a>
				<a class="uri" href="<?php h($uri)?>">uri</a>
				</dd>
			<?php endif; ?>
			<?php foreach($properties as $p => $objs):?>

				<dt title="<?php h($p) ?>"><?php echo ( isset($labels[$p]))? $labels[$p] : $p ?></dt>

				<?php foreach($objs as $o):?>
					<dd>
						<?php if (preg_match('/(jpg)|(gif)|(png)/', $o['value']) ):?>
							<img alt="image" src="<?php  h($o['value']) ?>"/>
						<?php elseif(isset($o['type']) 
						and isset($o['value']) 
						and $o['type']!='literal'):?>
						<?php $RDFa_link = 'resource="'.htmlentities($o['value']).'" rel="'. htmlentities($this->Convert->URI->to_qname($p, $this->namespaces)->value()).'"'; ?>
							<?php if(isset($resources[$o['value']])):?>
									<a href="#resource_<?php echo url_id($o['value']); ?>" <?php echo $RDFa_link ?>>
										<?php h(wordwrap($Resources->to_resource($o['value'])->get_title(),75,'\n', true)); ?>
									</a>
							<?php else:?>
								
								<a class="convert" href="/?data-uri=<?php echo urlencode(htmlentities($o['value'])); ?>&amp; format=html" <?php echo $RDFa_link ?>><?php h($o['value']); ?></a>
								<a class="uri" href="<?php h($o['value']); ?>">uri</a>
							<?php endif?>
						<?php elseif(isset($o['value'])):?>

							<span style="display:hidden" 
							property="<?php h($this->Convert->URI->to_qname($p, $this->namespaces)->value())?>" 
							xml:lang="<?php echo (isset($o['lang']))? $o['lang'] : ''?>" 
							datatype="<?php echo (isset($o['datatype']))? htmlentities($o['datatype']) : ''?>"><?php echo $this->Convert->GraphIndex->xmlencode($o['value'])?></span>
							
							
							<span xml:lang="<?php echo (isset($o['lang']))? $o['lang'] : ''?>"><?php h(strip_tags($o['value'],''))?></span>
							
						<?php endif?>
						
						<?php if(!empty($o['lang'])): ?><span class="lang_label"><?php h($o['lang'])?></span><?php endif?>
					</dd>
				<?php endforeach?>
			<?php endforeach?>
		</dl>
	</div></li>
<?php endforeach?>
</ol>
</div>
<?php else:?>
	<?php require('templates/sparql-results.html'); ?>
	<?php require('templates/facet.html'); ?>
<?php endif;?>